﻿namespace Masa.Alert.ApiGateways.Caller;

public class AlertCaller : DaprCallerBase
{
    private AlarmRuleService? _alarmRuleService;
    private AlarmHistoryService? _alarmHistoryService;
    private AlarmRuleRecordService? _alarmRuleRecordService;
    private WebHookService? _webHookService;

    public AlarmRuleService AlarmRuleService => _alarmRuleService ??= new(Caller);
    public AlarmHistoryService AlarmHistoryService => _alarmHistoryService ??= new(Caller);
    public AlarmRuleRecordService AlarmRuleRecordService => _alarmRuleRecordService ??= new(Caller);
    public WebHookService WebHookService => _webHookService ??= new(Caller);
    protected override string AppId { get; set; } = App.APP;

    protected override void UseDaprPost(MasaDaprClientBuilder masaDaprClientBuilder)
    {
        masaDaprClientBuilder.UseAuthentication((IServiceProvider serviceProvider) => new AuthenticationService(serviceProvider.GetRequiredService<TokenProvider>(), serviceProvider.GetRequiredService<JwtTokenValidator>()));
        base.UseDaprPost(masaDaprClientBuilder);
    }
}
